package colin.spring.boot.sample.web.service;

import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import colin.spring.boot.sample.web.dao.AticleDao;
import colin.spring.boot.sample.web.pojo.AticleEntity;

@Service
@Transactional
public class AticleService {
	@Autowired
	private AticleDao aticleDao;

	/**
	 * 
	 * 方法描述： 分页返回所有的文章 注意事项：
	 * 
	 * @param pageIndex
	 * @param pageSize
	 * @return
	 * @Exception 异常对象
	 */
	public Page<AticleEntity> findAllAticleByPage(int pageIndex, int pageSize) {
		Pageable pageable = new PageRequest(pageIndex, pageSize,
				Sort.Direction.ASC, "aticlecrtime");
		return aticleDao.findAll(pageable);
	}

	/*
	 * 保存文章
	 */
	public void saveAticle(Map<String, Object> params) {
		AticleEntity aticleEntity = new AticleEntity();
		aticleDao.save(aticleEntity);
	}
}
